package sb;

import java.util.Random;

public class demo1 {
    public static void main(String[] args) {
        method1();
        method2();
    }

    private static void method2() {
        //随机字符串长度不固定
        char[] chars = {'#', '$', '%', '&', '*', '@', ')'};
        Random r = new Random();
        for (int i = 1; i <= 6; i++) {
            StringBuilder sb = new StringBuilder();
            for (int j = 0; j < i + 1; j++) {
                int i1 = r.nextInt(i + 1);
                sb.append(chars[i1]);
            }
            System.out.println(i + " sb = " + sb);
        }
    }

    private static void method1() {
        // # $ % &
        char[] chars = {'#', '$', '%', '&'};
        StringBuilder sb = new StringBuilder();
        Random random = new Random();
        for (int i = 0; i < 6; i++) {
            sb.append(chars[random.nextInt(4)]);
        }
        System.out.println("sb = " + sb);
    }

}
